#pragma once
#include "DXGIAdapter.hpp"
#include "../UI/DirectXViewerControl.hpp"
namespace NAMESPACENAME
{
	class DirectXViewerControl;
	namespace DirectX
	{
		class D3D12CommandQueue;
		class DXGISwapChain;
		class DXGIFactory final
		{
		protected:
			IDXGIFactory7 * factory;
			inline DXGIFactory(IDXGIFactory7* factory) :
				factory(factory)
			{
			}
		public:
			static inline DXGIFactory* Create(bool debug)
			{
				if (IDXGIFactory7* fact	;SUCCEEDED(CreateDXGIFactory2(debug ? DXGI_CREATE_FACTORY_DEBUG : 0, IID_PPV_ARGS(&fact))))
					return new DXGIFactory(fact);
				return nullptr;
			}
			virtual ~DXGIFactory();
			DXGIAdapter* EnumAdapters(UINT Adapter)const;
			inline DXGIAdapter* EnumAdapterByGpuPreference(UINT Adapter, DXGI_GPU_PREFERENCE GpuPreference)const
			{
				if (IDXGIAdapter4* adapter; SUCCEEDED(factory->EnumAdapterByGpuPreference(Adapter, GpuPreference, IID_PPV_ARGS(&adapter))))
					return new DXGIAdapter(adapter);
				return nullptr;
			}
			DXGISwapChain* CreateSwapChain(
				D3D12CommandQueue* commandQueue,
				NAMESPACENAME::DirectXViewerControl* viewer,
				const DXGI_SWAP_CHAIN_DESC1* pDesc,
				const DXGI_SWAP_CHAIN_FULLSCREEN_DESC* pFullScreenDesc,
				IDXGIOutput* pRestrictToOutput
			)const;
			inline bool MakeWindowAssociation(DirectXViewerControl* viewer, UINT flags)const
			{
				return SUCCEEDED(factory->MakeWindowAssociation(viewer->WindowHandle(), flags));
			}
		};
	}
}